<style type="text/css">
.normal_form[form-role="dialog"] {padding-top:30px;}
.normal_form[form-role="dialog"] .row.require .select-defined{background-color:#fffbe8;}
.normal_form[form-role="dialog"] .row .field_text {width:150px;}
.normal_form[form-role="dialog"] .input-text{width:150px;}
.normal_form .select-defined-content .select-box-content .select-dl {max-height:280px;}
.normal_form[form-role="dialog"] .input-image {}
.normal_form[form-role="dialog"] .image-uploader{width:350px;height: 180px; line-height: 180px;background-color: #f2f2f2; text-align: center; margin-left:185px;;}
</style>
<form name="dialogform" class="normal_form row-inline" form-role="dialog" onsubmit="return Core.Sys.Dialogform(this);" autocomplete="off">
    <div class="row" style="width:100%;">
        <div class="field_text require">门店名称：</div>
        <input type="text" class="input-text require" name="title" value="{$res['title'] ?? ''}" maxlength="100" placeholder="请输入门店名称" style="width:510px;" />
    </div>
    <div class="row require">
        <div class="field_text require">城市区域：</div>
        <select class="zs-select-group oselectregion" name="region" data-selected="{$res['province'] ?? 0},{$res['city'] ?? 0},{$res['county'] ?? 0}" data-title="省份,城市,区域" data-holder="请选择省份/城市/区域" data-style="width:510px;"></select>
    </div>
    <div class="row">
        <div class="field_text">详细地址：</div>
        <input type="text" class="input-text" name="address" value="{$res['address'] ?? ''}" maxlength="200" placeholder="请输入详细地址" style="width:510px;" />
    </div>
    <div class="row" style="width:360px;">
        <div class="field_text">联络人姓名：</div>
        <input type="text" class="input-text require" name="lnname" value="{$res['lnname'] ?? ''}" maxlength="20" placeholder="请输入联络人姓名" />
    </div>
    <div class="row">
        <div class="field_text">联络人手机：</div>
        <input type="text" class="input-text require" name="lnphone" value="{$res['lnphone'] ?? ''}" maxlength="11" placeholder="请输入手机号码" />
    </div>
    <div class="row" style="width:360px;">
        <div class="field_text">GPS经度：</div>
        <input type="text" class="input-text require" name="lng" value="{$res['lng'] ?? ''}" maxlength="15" placeholder="请输入GPS经度" />
    </div>
    <div class="row">
        <div class="field_text">GPS纬度：</div>
        <input type="text" class="input-text require" name="lat" value="{$res['lat'] ?? ''}" maxlength="15" placeholder="请输入GPS纬度" />
    </div>    
    <div class="row" style="width:360px;">
        <div class="field_text">起始免费时长：</div>
        <input type="text" class="input-text require" name="trial" value="{$res['trial'] ?? ''}" maxlength="15" placeholder="请设置起始免费时长" /> <span style="color:gray;">单位:分钟</span>
    </div>
    <div class="row">
        <div class="field_text">起始特饮费：</div>
        <input type="text" class="input-text require" name="juice" value="{$res['juice'] ?? ''}" maxlength="15" placeholder="请输入起始{$Think.config.conf.goodscost ?? ''}(小时价),单位:元" /> <span style="color:gray;">{$Think.config.conf.goodscost ?? ''}(小时价)单位:元</span>
    </div>
    <div class="row" style="width:360px;">
        <div class="field_text">封顶时长：</div>
        <input type="text" class="input-text require" name="capped" value="{$res['capped'] ?? ''}" maxlength="15" placeholder="请设置封顶时长" /> <span style="color:gray;">单位:分钟</span>
    </div>
    <div class="row">
        <div class="field_text">起步时长：</div>
        <div class="labelrow">
            <label class="l-checkbox"><input type="checkbox" name="gtdmin" value="1" {if ($res['gtdmin'] ?? NULL)}checked{/if} /><i></i><span>开启</span></label>
        </div>
    </div>
    <div class="row" data-key="kdefer" style="width:100%;">
        <div class="field_text">订单归档时间点：</div>
        <input id="kdefer" name="kdefer" class="input-text time-spinner" min="00:00" max="23:59" value="{$res['kdefer'] ?? '00:00'}" showSeconds="false" placeholder="请配置时间" > 前，
        <span style="color:gray;"><span style="color:red;">次日该时间点前</span>为当日订单。</span>
    </div>
    <div class="row" data-key="attn" style="width:360px;">
        <div class="field_text">上班打卡时间：</div>
        <input id="attns" name="attns" class="input-text time-spinner" min="00:00" max="23:59" value="{$res['attns'] ?? '00:00'}" showSeconds="false" placeholder="请配置时间" >
        <!--
        <input id="attne" name="attne" class="input-text time-spinner" min="00:00" max="23:59" value="{$res['attne'] ?? '00:00'}" showSeconds="false" style="width:108px;" placeholder="请配置时间" >
        <span style="color:gray;">上班时间必须晚于订单归档时间点。</span>
        -->
    </div>
    <div class="row">
        <div class="field_text">打卡间距：</div>
        <input type="text" class="input-text require" name="attndis" value="{$res['attndis'] ?? ''}" maxlength="15" placeholder="请输入GPS定位间距,单位米" />
        <span style="color:gray;text-indent:180px;margin-bottom:5px;">GPS定位间距,单位米</span>
    </div>
    <div class="row" style="width:100%;">
        <div class="field_text">会员优惠方案：</div>
        <select class="z-select uvip" name="uvip" data-style="width:150px;display: inline-block;" data-prompt="请选择方案...">
            <option value="">请选择方案...</option>
            <option value="1" {if ($res['uvip'] ?? 0)==1} selected{/if}>免费天数</option>
            <option value="2" {if ($res['uvip'] ?? 0)==2} selected{/if}>赠送至日期</option>
        </select>
    </div>
    <div class="row" data-key="uvip-0" style="width:360px;display:none;">
        <div class="field_text">方案截止日期：</div>
        <input type="text" class="input-text require date-ico" name="uvipend" value="{$res['uvipend'] ?? ''}" placeholder="方案截止日期" data-options="seconds:true" style="width:150px;" />
    </div>
    <div class="row" data-key="uvip-1" style="display:none;">
        <div class="field_text">免费天数：</div>
        <input type="text" class="input-text require" name="uvipnum" value="{$res['uvipnum'] ?? ''}" placeholder="免费天数" style="width:150px;" />
        <span style="color:gray;text-indent:180px;margin-bottom:5px;">最多9999天</span>
    </div>
    <div class="row" data-key="uvip-2" style="display:none;">
        <div class="field_text">赠送至日期：</div>
        <input type="text" class="input-text require date-ico" name="uvipday" value="{$res['uvipday'] ?? ''}" placeholder="赠送至日期" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',startDate:'{%y+1}-%M-%d',minDate:'%y-%M-{%d+1}'})" style="width:150px;" />
    </div>
    
    <div class="row" style="width:100%;">
        <div class="field_text require">服务终止时间：</div>
        <input type="text" class="input-text require date-ico" name="etime" value="{$res['etime'] ?? ''}"  placeholder="请设置服务终止时间" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',startDate:'{%y+1}-%M-%d',minDate:'%y-%M-{%d+1}'})" style="width:150px;" /> <span style="color:gray;">注意：终止后系统将无法进入</span>
    </div>
    <div class="row form-footer-bar">
        <p class="colortip"></p>
        <button class="btn" role="btn-cancel">取消</button>
        <button class="btn btn-primary" type="submit" role="btn-submit">保存</button>
    </div>
</form>
<script type="text/javascript">
Core.Sys.Dialogform = function(form){
    var form = $(form);
    var p    = {
        'title'    : form.find(":text[name='title']").val(),
        'province' : 0,
        'city'     : 0,
        'county'   : 0,   
        'address'  : form.find(":text[name='address']").val(),
        'lnname'   : form.find(":text[name='lnname']").val(),
        'lnphone'  : form.find(":text[name='lnphone']").val(),
        'lng'      : form.find(":text[name='lng']").val(),
        'lat'      : form.find(":text[name='lat']").val(),
        'trial'    : form.find(":text[name='trial']").val(),
        'juice'    : form.find(":text[name='juice']").val(),
        'capped'   : form.find(":text[name='capped']").val(),
        'gtdmin'   : 0,
        'kdefer'   : form.find('#kdefer').val(),
        'attns'    : form.find("#attns").val(),
        //'attne'    : form.find("#attne").val(),
        'attndis'  : form.find(":text[name='attndis']").val(),
        'uvip'     : form.find(".uvip").getZsValue(),
        'uvipend'  : form.find(":text[name='uvipend']").val(),//方案截止日期
        'uvipnum'  : form.find(":text[name='uvipnum']").val(),
        'uvipday'  : form.find(":text[name='uvipday']").val(),
        'etime'    : form.find(":text[name='etime']").val(),
	}
    if (!Core.rule('*',p['title'])){
		form.find("p.colortip").html('请输入门店名称!');return false;
	}
    var region  = $('.oselectregion').oGetSelectVal();
    var regions = region.split(',');
    p['province'] = regions[0] || 0;
    p['city'] = regions[1] || 0;
    p['county'] = regions[2] || 0;
    if (region == '') {
        form.find("p.colortip").html('请选择城市区域!');return false;
    }
    if (!Core.rule('intp',p['province']) || !Core.rule('intp',p['city']) || !Core.rule('intp',p['county'])){
		form.find("p.colortip").html('请选择城市区域!');return false;
	}
    if ((p['lng']!='' || p['lat']!='') && (!Core.rule('dblps',p['lng']) || !Core.rule('dblps',p['lat']))) {
        form.find("p.colortip").html('请输设置正确的经纬度!');return false;
    } else if (!Core.rule('money',p['juice'])) {
        form.find("p.colortip").html("请输入{$Think.config.conf.goodscost ?? ''}(小时价),单位元!");return false;
    }
    if ($(':checkbox[name="gtdmin"]').prop('checked')) {
        p['gtdmin'] = 1;
    }
    let t;
    let Tkeys = ['kdefer','attns'];//,'attne'
    for(i in Tkeys) {
        t = {
            H : $('#'+Tkeys[i]).timespinner('getHours'),
            i : $('#'+Tkeys[i]).timespinner('getMinutes'),
        }
        if (p[Tkeys[i]] != '' && (!Core.rule('intps',t.H) || !Core.rule('intps',t.i))) {
            form.find("p.colortip").html('请配置正确的'+({"kdefer" : '归档',"attns" : '上班',"attne" : '下班'}[Tkeys[i]] || '')+'时间点!');return false;
        }
    }
    if (!Core.rule('intps',p['attndis'])){
        form.find("p.colortip").html('请设置正确的打卡间距!');return false;
    }
    if (Core.rule('intp',p['uvip'])){
        if (p['uvipend']!='' && !Core.rule('datetime',p['uvipend'])){
            form.find("p.colortip").html('请设置方案截止日期!');return false;
        }
        //免费天数
        if (p['uvip'] == "1") {
            if (!Core.rule('intp',p['uvipnum'])){
                form.find("p.colortip").html('请设置免费天数!');return false;
            }
        } else if (p['uvip'] == "2") {
            //赠送至日期
            if (!Core.rule('datetime',p['uvipday'])){
                form.find("p.colortip").html('请设置赠送至日期!');return false;
            }
        }
    }
    if (!Core.rule('datetime',p['etime'])){
        form.find("p.colortip").html('请设置服务终止时间!');return false;
    } 

	form.find(":button").attr('disabled','disabled');
	$.ajax({type : "POST",dataType: "json",cache : false, url : "{$_G['_mc_']}/edit/id/{$res['id'] ?? ''}?r="+Math.random(),data : p,success: function(data){
	   try{
		   if (data['state'] == 'y'){
                $('#datalist').datagrid('reload');$(form).dialogClose();
		   } else {
                form.find(":button").removeAttr('disabled');form.find("p.colortip").html(data['msg']);return false;
		   }
	   }catch(e){form.find(":button").removeAttr('disabled');form.find("p.colortip").html('数据提交失败!');return false;}
	}});
	return false;
}
Core.Sys.Uvip = function(vkey){
    $('div[data-key="uvip-0"]').hide();
    $('div[data-key="uvip-1"]').hide();
    $('div[data-key="uvip-2"]').hide();
    if (!Core.rule('intps',vkey) || $.inArray(vkey,['1','2'])==-1) return;
    $('div[data-key="uvip-0"]').show();
    $('div[data-key="uvip-'+vkey+'"]').show();
}
$(function(){
    Core.easyloaderInit();
    $('.oselectregion').oselect([{
        type: 'easyui',
        url: "/index.ajax/district/level/1",
        fieldv: 'id',
        fieldt: 'name',
        filter: function(result) {
            return result['rows'];
        }
    },{
        type: 'easyui',
         url: "/index.ajax/district/level/2/pid/@parentValue",
        fieldv: 'id',
        fieldt: 'name',
        filter: function(result) {
            return result['rows'];
        }
    },{
        type: 'easyui',
         url: "/index.ajax/district/level/3/pid/@parentValue",
        fieldv: 'id',
        fieldt: 'name',
        filter: function(result) {
            return result['rows'];
        }
    }], function (event, elem, id, txt) {
        // console.log('oselectseries:', id, '|', txt);
    });
    $(".uvip").on('setZsValue',function(){
        var vkey = $(this).getZsValue();
        Core.Sys.Uvip(vkey);
    });
});
</script>